﻿using GroceryList.Domain.Model.GroceryList;
using GroceryList.Model;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Type;

namespace GroceryList.Domain.Mapping
{
    public class ListaCompraMap : ClassMapping<ListaCompra>
    {
        public ListaCompraMap()
        {
            Id(
                "Id",
                ma => {
                    ma.Type(new GuidType());
                    ma.Column("Id");
                    ma.Generator(new GuidGeneratorDef());
                });
            this.NaturalId(ni=>ni.
                Property(lc=>lc.Codigo));
            Property(lc => lc.Nombre);
            Property(lc => lc.Fecha);
            Set(
                lc => lc.DetalleProducto,
                map => 
                {
                    map.Key(k =>
                        k.Column("ListaCompraId"));
                    map.Access(Accessor.NoSetter);
                    map.Cascade(Cascade.All);
                    
                },ce=>ce.OneToMany()
            );
        }
    }
}